<?php
header("content-type:text/html;charset=utf-8");
$dsn="mysql:host=127.0.0.1;dbname=book;charset=utf8";
$pdo=new PDO($dsn,'root','root');
$sql="select * from qg";
$res=$pdo->query($sql);
$data=$res->fetchAll(PDO::FETCH_ASSOC);
?>
<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
  <center>
      <div>倒计时 <span id="hour">时</span><span id="min">分</span><span id="sec">秒</span></div>
      <table border="1">
          <tr>
              <td>商品名</td>
              <td>商品数量</td>
              <td>原价</td>
              <td>惊爆价</td>
              <td>操作</td>
          </tr>
          <?php foreach ($data as $v) {?>
          <tr>
              <td><?php echo $v['qg_name']?></td>
              <td><?php echo $v['number']?></td>
              <td><?php echo $v['price']?></td>
              <td>￥6.00</td>
              <td>
                  <input type="button" id="qw" value="抢购" qian="<?php echo $v['id']?>">
              </td>
          </tr>
          <?php }?>
      </table>
  </center>
</body>
</html>
　　　<script src="jquery-3.3.1.min.js"></script>
<script>
    window.setInterval(function () {
        $.getJSON('time.php',"",function (e) {
            $("#hour").html(e.hour+"时");
            $("#min").html(e.hour+"分");
            $("#sec").html(e.hour+"秒");
        },);
    },1000);
   $("#qw").click(function () {
       var id=$(this).attr("qian");
       $.ajax({
           url:"qiang.php",
           data:{id:id},
           dataType:"json",
           type:"post",
           success:function (res) {
               alert(res.msg);
               location.reload();
           }
       });
   });
</script>


